package com.chenzhe.apijieshou.util;

import com.chenzhe.apijieshou.util.base64.Base64 ;
import com.chenzhe.apijieshou.util.httputil.HttpUtil ;

import java.util.Map;

public class SendDataUtil {
    public static String sendDataToYingDa(Map<String,String> maps, String JSON, String privateKey)  {


        //AES加密
        String randomString =AESRandomKey.getRandomString(5);
        System.out.println(randomString+"  密钥");
        byte[] encodedData =null;
        try{
            encodedData = RSAUtils.encryptByPrivateKey(randomString.getBytes(), privateKey);
        }catch(Exception e){
            e.printStackTrace();
        }
        //加密 密钥
        byte[] bytes = Base64.encodeBase64(encodedData);
        String s = new String(bytes);
        String key = s.replace("+", "%2B");
        maps.put("key",key);

        byte[] rawKey = AESUtil.getRawKey(randomString.getBytes());
        byte[] encrypt = AESUtil.encrypt(rawKey, JSON);
        System.out.println(randomString+"    key1");



        //String s3 = HttpUtil.getInstance().sendHttpPost("http://localhost:9090/api?a=123&b=456&key=" + s1, encrypt);
        return HttpUtil.getInstance().sendHttpPost(maps, encrypt);
    }
}
